home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_6.arc / WINDEV.ARC / WINAUXFN.C < prev    next >
C/C++ Source or Header  |  1989-08-05  |  4KB  |  160 lines

  1. /* 
  2.  * Winaux functions module
  3.  *
  4.  * Written by Bill Hall
  5.  * 3665  Benton Street, #66
  6.  * Santa Clara, CA 95051
  7.  *
  8.  */
  9.  
  10. #define NOCOMM
  11. #define NOKANJI
  12. #define NOMINMAX
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <fcntl.h>
  16. #include <io.h>
  17. #include <stdio.h>
  18. #include <ascii.h>
  19. #include <windows.h>
  20. #include <ttycls.h>
  21. #include "winaux.h"
  22.  
  23. /* local function declaractions */
  24. static void NEAR ShowAboutBox(HWND hWnd);
  25.  
  26. void NEAR DispatchString(HWND hWnd, WORD wParam, LONG lParam)
  27. {
  28. #define LBUFLEN    100
  29.  
  30.     BYTE buf[LBUFLEN];
  31.     int len, i, count;
  32.     
  33.     len = (int)wParam;
  34.     
  35.     while (len > 0) { /* read and dispatch each part of buffer until done */                                
  36.     count = min(len, LBUFLEN);
  37.     for (i = 0; i < count; i++)
  38.         buf[i] = *(LPSTR)lParam++;
  39.         TTYDisplay((PTTYWND)GetWindowWord(hWnd,0),(short)count, buf);
  40.     if (LogToFile)
  41.         write(hFile, buf, count);
  42.     len -= count;
  43.     }    
  44. }
  45.  
  46. static void NEAR ShowAboutBox(HWND hWnd)
  47. {
  48.  
  49.     FARPROC fp;
  50.     HANDLE hInstance = GetWindowWord(hWnd, GWW_HINSTANCE);
  51.  
  52.   /* make a proc instance for the about box window function */
  53.     fp = MakeProcInstance((FARPROC)AboutBoxProc, hInstance);
  54.   /* create a modal dialog box */
  55.     DialogBox(hInstance, MAKEINTRESOURCE(DT_ABOUT),hWnd,fp);
  56. }
  57.  
  58. /* process the menu */
  59. void NEAR WndCommand(HWND hWnd, WORD wParam)
  60. {
  61.  
  62.     HMENU hMenu = GetMenu(hWnd);
  63.  
  64.     switch (wParam) {
  65.  
  66.     case IDM_LOG:
  67.         if (LogToFile)
  68.             write(hFile, szEndLog, strlen(szEndLog));
  69.         else 
  70.         write(hFile, szBeginLog, strlen(szBeginLog));
  71.         LogToFile = (LogToFile ? FALSE : TRUE);
  72.             CheckMenuItem(hMenu,wParam,LogToFile ? MF_CHECKED : MF_UNCHECKED);
  73.         break;
  74.  
  75.     case IDM_ABOUT:
  76.         ShowAboutBox(hWnd);
  77.         break;
  78.  
  79.     case IDM_CRONLF:
  80.         MWnd.CRonLF = (MWnd.CRonLF ? FALSE : TRUE);
  81.         CheckMenuItem(hMenu,wParam,MWnd.CRonLF ? MF_CHECKED : MF_UNCHECKED);
  82.         break;
  83.  
  84.     case IDM_CLEAR:
  85.         TTYClear(&MWnd);
  86.         break;
  87.     }
  88. }
  89.  
  90. /* paint the main window */
  91. void NEAR MainWndPaint(hWnd, lpps)
  92. HWND hWnd;
  93. LPPAINTSTRUCT lpps;
  94. {
  95.  
  96.     HDC hDC = lpps->hdc;
  97.  
  98.   /* if the window is iconic, draw the icon */
  99.     if (IsIconic(hWnd)) {
  100.     RECT rIcon;
  101.     GetClientRect(hWnd, (LPRECT)&rIcon);
  102.     Rectangle(hDC, 0,0,rIcon.right, rIcon.bottom);
  103.         TextOut(hDC,2,rIcon.bottom/3,(LPSTR)szIconTitle,strlen(szIconTitle));
  104.     }
  105.   /* otherwise update the text in the window */
  106.     else 
  107.     TTYWndPaint(&MWnd, lpps->hdc, lpps->rcPaint.top, lpps->rcPaint.bottom);
  108. }
  109.  
  110. /* set the window handle variable */
  111. int SetWinIni(HWND hWnd)
  112. {
  113.     char buf[20];
  114.     return (WriteProfileString((LPSTR)szAppName, (LPSTR)szhWnd, 
  115.             (LPSTR)itoa(hWnd, buf, 10)));
  116. }
  117.  
  118. /* adjust where text is to be displayed if window is resized */
  119. void NEAR AdjustHeight(short width, short height)
  120. {
  121.      
  122.     MWnd.Width = width;
  123.     MWnd.Height = height;
  124.     MWnd.Pos.y = height - MWnd.CHeight - 1;
  125.     InvalidateRect(MWnd.hWnd, (LPRECT)NULL, TRUE);
  126. }
  127.  
  128. /* This is the window proc for the about box when it is displayed */
  129. BOOL FAR PASCAL AboutBoxProc(hDlg, message, wParam, lParam)
  130. HWND hDlg;
  131. unsigned message;
  132. WORD wParam;
  133. LONG lParam;
  134. {
  135.  
  136.     switch (message) {
  137.  
  138.       /* nothing to initialize */
  139.     case WM_INITDIALOG:
  140.         break;
  141.  
  142.       /* this dialog box has only an OK button */
  143.     case WM_COMMAND:
  144.         switch (wParam) {
  145.         case IDOK:
  146.         case IDCANCEL:
  147.         /* destroy the dialog box */
  148.             EndDialog(hDlg,TRUE);
  149.             break;
  150.         default:
  151.             return FALSE;        /* we did not process */
  152.         }
  153.         break;
  154.         
  155.     default:
  156.         return FALSE;
  157.     }
  158.     return TRUE;        /* we processed message */
  159. }
  160.